import { ESTerrainLayer, ESImageryLayer } from 'earthsdk3'
import { ref } from 'vue'

export const imageryLayer = ref(null)
// 添加影像
const addESImageryLayer = (objm) => {
  imageryLayer.value = objm.createSceneObject(ESImageryLayer)
  if (!imageryLayer.value) return
  imageryLayer.value.url =
    'https://server.arcgisonline.com/arcgis/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}'
  imageryLayer.value.zIndex = 1
}

// 添加地形
const addESTerrainLayer = (objm) => {
  const sceneObject = objm.createSceneObject(ESTerrainLayer)
  if (!sceneObject) return
  sceneObject.url = 'http://114.242.26.126:6003/terrain/globe/layer.json'
}

const changeImageLayerShow = (state) => {
  if (!imageryLayer.value) return
  imageryLayer.value.show = state
}

// 批量导出（对象形式）
export { addESImageryLayer, addESTerrainLayer, changeImageLayerShow }

// import { ESTerrainLayer, ESImageryLayer } from 'earthsdk3'

// export default (objm) => {
//   function addESImageryLayer() {
//     const sceneObject = objm.createSceneObject(ESImageryLayer)
//     if (!sceneObject) return
//     sceneObject.url =
//       'https://server.arcgisonline.com/arcgis/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}'
//     sceneObject.zIndex = 1
//   }

//   function addESTerrainLayer() {
//     const sceneObject = objm.createSceneObject(ESTerrainLayer)
//     if (!sceneObject) return
//     sceneObject.url = 'http://114.242.26.126:6003/terrain/globe/layer.json'
//   }
//   addESImageryLayer()
//   addESTerrainLayer()
// }
